package top.gongtao.tencent.cos.tencentcosweb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import top.gongtao.tencent.cos.tencentcosweb.common.constant.ConstString;
import top.gongtao.tencent.cos.tencentcosweb.utils.UploadFileUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Created by gongtao on 2017/11/11 18:08.
 */

@Controller
@RequestMapping(value="/user",produces = {ConstString.APP_JSON_UTF_8})
public class UserController {

    @PostMapping("/save")
    public String save(HttpServletRequest request, Model model) throws Exception {
        List fileList = UploadFileUtil.uploadFile(request);
        model.addAttribute("result", (String) ((Map) fileList.get(0)).get("result"));
        return "save_result";
    }

    @RequestMapping(value="index")
    public String index(){
        return "index";
    }
}